<?php
namespace app\admin\controller;

use think\Controller;
use think\Request;
use think\Db;
use think\Cookie;
use think\Session;

class Login extends Controller
{

    public function index()
    {
        if(Request::instance()->isAjax()){
            $username= filter_keyword(input('post.username'));
            $password = filter_keyword(input('post.password'));
            $remember = filter_keyword(input('post.remember'));

            $res = Db::connect('user_db')->query('select * from s_manage where uname = "'.$username.'" limit 1');
            if($res[0]['upass']==md5($password)){
                Session::set('username',$username);
                if($remember=='on'){
                    Cookie::set("username",$username);
                }
                $data['msg'] = '登录成功';
                $data['code'] = '1009';
                $data['data'] = '';
            } else {
                $data['msg'] = '登录失败';
                $data['code'] = '1001';
                $data['data'] = '';
            }
            return $data;
        } else {
            return view('index');
        }
    }

}